package com.mallcai.bigdata.ladon.controller.common.form;

import com.mallcai.bigdata.ladon.controller.BaseForm;
import com.mallcai.bigdata.ladon.dpl.entity.common.Datasource;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-05-22 11:16.
 * Modify:
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class DataSourceForm extends BaseForm {
    @NotNull(message = "主键Id不能为空", groups = {IdCheck.class, EditCheck.class, ChangeStatusCheck.class})
    private Long    dsId;
    @NotBlank(message = "数据源类型不能为空", groups = {AddCheck.class, EditCheck.class})
    private String  type;       // 数据源类型
    @NotBlank(message = "数据源名称不能为空", groups = {AddCheck.class, EditCheck.class})
    private String  name;       // 名称
    @NotNull(message = "数据源状态不能为空", groups = {ChangeStatusCheck.class})
    private Integer status;     // 状态, 0 - active; 1 - disabled
    @NotBlank(message = "数据源驱动不能为空", groups = {AddCheck.class, EditCheck.class})
    private String  jdbcDriver; // jdbc驱动
    @NotBlank(message = "数据源URL不能为空", groups = {AddCheck.class, EditCheck.class})
    private String  jdbcUrl;    // jdbc URL
    private String  username;   // 登录名
    private String  password;   // 登录密码
    private Integer timeout;    // 连接池超时时间(ms)
    private String  testSql;    // 检测SQL
    private Byte  useType;    // 用途

    public Datasource toEntity() {
        Datasource ds = new Datasource();

        BeanUtils.copyProperties(this, ds);
        ds.setId(dsId);
        return ds;
    }

    public interface IdCheck {
    }

    public interface AddCheck {
    }

    public interface EditCheck {
    }

    public interface ChangeStatusCheck {
    }
}
